Fix failure to execute tool post-install script on Windows #897
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
Tool Dependency Installation
Arduino Create Agent performs installation and updates of the tool dependencies required for direct communication between the local machine and the target board.
It might be necessary to execute some sort of installation process in addition to placing the files from the tool archive on the user's hard drive. This capability is provided by a "post-install script" system. If a post-install script file (
post_install.bat
on Windows,post_install.sh
other host operating systems) is found in the tool installation, Arduino Create Agent automatically executes it as part of the tool installation operation.One of the tool dependencies is
arduino:windows-drivers
, which provides the Windows device drivers for the official Arduino boards. This tool contains a post-install script that installs the drivers from the tool archive. It is essential for this script to be executed as the presence of the driver files alone doesn't have any effect.Go
exec
PackageFrom the Go 1.19 release, the behavior of the
exec
package was changed to make it more secure:https://pkg.go.dev/os/exec#hdr-Executables_in_the_current_directory
Problem
The code that executes the post-install script on Windows depended on the previous permissive behavior of the
exec
package. Ever since the version of Go used to build Arduino Create Agent was updated to 1.19 (#744), the script has not been executed.This means Arduino Create Agent never installed the drivers from the
arduino:windows-drivers
tool on the machines who weren't using it before the 1.3.0 release.The failure to execute the post-install script results in Arduino Create Agent attempting installation of the
arduino:windows-drivers
tool on every Arduino Cloud session. Even if the user is not impacted by the lack of drivers (either because it is not required for their board, or because they installed the drivers via some other mechanism), they will still be annoyed and confused by the frequent appearance of the "Installing drivers" dialog that is produced by Arduino Create Agent's post-install script execution code.Demonstration
arduino:windows-drivers
tool even if you already have the latest version installed.🐛 Arduino Create Agent does not execute the
post_install.bat
batch file. You can see the cause in the Arduino Create Agent debug console:Additional Context
I planned to add test coverage for
github.com/arduino/arduino-create-agent/tools.Tools.installDrivers
in order to avoid another such regression in the future. However, this is challenging to do for Windows due to the "Installing drivers" dialog. It seems it would be necessary to mockgithub.com/arduino/arduino-create-agent/tools.MessageBox
, which would require selecting a mocking framework for the project.I chose the approach that followed the system previously established in the code. A more elegant solution would be possible through the use of the the
github.com/arduino/go-paths-helper
module, which is already used elsewhere in the project. However, I feel that should be done as part of comprehensive migration to using the module for all path-related operations, which is out of scope for this PR.I didn't have time to investigate it, but it is possible this will fix #856.
Originally reported at: